﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace WebSimpleCalculator
{
    public partial class SimpleCalculator : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {

        }

        protected void Calculate_Click(object sender, EventArgs e)
        {
            decimal firstNumber = 0;
            decimal secondNumber = 0;

            if (!decimal.TryParse(this.firstNumberTextBox.Text, out firstNumber))
            {
                this.result.Text = "Wrong input for the first number";
                return;
            }

            if (!decimal.TryParse(this.secondNumberTextBox.Text, out secondNumber))
            {
                this.result.Text = "Wrong input for the second number";
                return;
            }

            switch (this.operation.SelectedValue)
            {
                case "1":
                    {
                        this.result.Text = (firstNumber * secondNumber).ToString();
                        break;
                    }
                case "2":
                    {
                        this.result.Text = (firstNumber / secondNumber).ToString();
                        break;
                    }
                case "3":
                    {
                        this.result.Text = (firstNumber + secondNumber).ToString();
                        break;
                    }
                case "4":
                    {
                        this.result.Text = (firstNumber - secondNumber).ToString();
                        break;
                    }
            }
        }
    }
}